**Set directory to the Replicationgovernance\finkelextension folder

cd "XXX\ReplicationGovernance\Finkelextension"

* .do file that generated .dta file for percent of foreign assistance given to a country "military assitance priority"

import delimited "us_foreign_aid_completecsv.csv", encoding(UTF-8) 

*drop obligations, keep only disbursements---which we have starting in 2001
drop if transaction_type_name=="Obligations"

*destring fiscal_year, which used to have some typos that made it string.
destring fiscal_year, replace

*drop regional aid information

drop if country_id>999

drop if fiscal_year<2001

*we will not have other data for 2019
drop if fiscal_year>2018

*gen total military assistance to world in foreign aid data

sort fiscal_year
by fiscal_year: egen militaryaidtotal=sum(constant_amount) if assistance_category_id==2
by fiscal_year: egen militaryaidtotalmax=max(militaryaidtotal)
replace militaryaidtotalmax=0 if militaryaidtotalmax==.

*gen the total figure of military assistance for each country

sort country_code fiscal_year
by country_code fiscal_year: egen militaryaid=sum(constant_amount) if assistance_category_id==2
by country_code fiscal_year: egen militaryaidmax=max(militaryaid)
replace militaryaidmax=0 if militaryaidmax==.

*Generate country percentage of overall military assistance (FPP01 variable from Finkel et al)

gen globalsecuritypercent=militaryaidmax/militaryaidtotalmax

*****clean up

*generate tag for single observation to keep for each country_id

egen singlecountryyear=tag(fiscal_year country_id)

*drop all excess data to get down to country-year level of aggregation

keep if singlecountryyear==1

*keep only variable of interest at the country year level.

keep country_id country_code country_name fiscal_year globalsecuritypercent

*rename variables to merge in v-dem full rank data

rename fiscal_year year
rename country_code country_text_id

*drop cases made to unclear distributions between former countries/regions that are separate from their component countries, which are also in the data.

drop if country_text_id=="SCG"
drop if country_text_id=="SDF"

*Save so that it can be merged into vdem v9.

save "FPPdata20012018.dta", replace







